import React from "react";
import { Input, Form } from "antd";
import { genWidget } from "../core";
import ItemLayout, { WrapProps } from "./formLabel";

export const genTextWidget = (c: WidgetCategory): TextWidget => {
  const base = genWidget(c);
  return { ...base, label: "文本", placeholder: "请输入文本内容" };
};

const TextWidgetRender = (props: WrapProps) => {
  const { isview, placeholder, isRequired, name } = props;
  return (
    <ItemLayout {...props}>
      {!isview && <Input placeholder={placeholder} />}
      {isview && (
        <Form.Item
          name={name}
          required={isRequired}
          rules={[
            {
              required: isRequired,
              message: placeholder,
            },
          ]}
        >
          <Input placeholder={placeholder} />
        </Form.Item>
      )}
    </ItemLayout>
  );
};

export default TextWidgetRender;
